/*
 * recursion.cpp
 *
 *  Created on: Jul 2, 2011
 *      Author: denis
 */
#include "pent_low.h"
#include "constants.h"
#include "init_pent.h"

int Recursion(Pentamino_Low * executor,int depth) {
		int l_depth=depth;
		unsigned long long current_position = 0;
		unsigned long long bit_intersection = 0;
		unsigned long long bit_union = 0;
	    unsigned long long default_current_position =0;
	    unsigned long long elev_default_current_position =0;
		longvector l_rotations;
		longvector elev_rotations;
		longvector::iterator rotation,elev_rotation;


		l_rotations=*(executor->rot_depth(l_depth));
		int xsubs=0;
		int ysubs=0;

		int temp=0;
		//for (rotation = l_rotations.begin(); rotation!= l_rotations.end(); rotation++) {
		//std::cout<<depth<<';';
		for( int count=0;count<l_rotations.size();count++){




			executor->CheckRegions(((~(1074791427))^(~(4299167748)))&ALLOWED_BITS);
			executor->Check11((~(4299167748))&ALLOWED_BITS);
			default_current_position=l_rotations[count];
			xsubs=executor->xsubs(default_current_position);
			ysubs=executor->ysubs(default_current_position);
			executor->cur_fil_upd();
			for (int ycount = Y_MIN; ycount < Y_MAX-ysubs; ycount++) {
				current_position = (default_current_position >> ((X_MAX)* ycount));
				for (int xcount = X_MIN; xcount < X_MAX-xsubs; xcount++) {
					bit_intersection=current_position & (executor->current_field_status);
					bit_union=(current_position ^ executor->current_field_status);
					if ((bit_intersection== 0)&&(executor->CheckRegions(bit_union))) {
						executor->iprevious_steps_array->push_back(current_position);
						if (l_depth == 10) {
							//print_int(bit_union);
							//executor->iprevious_steps_array->pop_back();
							if( executor->Check11(bit_union)){
								executor->iprevious_steps_array->push_back((~bit_union)&ALLOWED_BITS);
								executor->printsolution();
							}
							executor->trim_to_depth(10);
							executor->cur_fil_upd();



						} else {
									Recursion(executor,l_depth+1);
									executor->trim_to_depth(l_depth);
									executor->cur_fil_upd();
									//executor->iprevious_steps_array->pop_back();
						}
					}
					current_position = (current_position >> 1)& LEFT_NULL_COLUMN;

			}
		}
	}
	return 0;
};
